package org.example;

public class Factory {
    private Factory() {
    }

    public static IMessage messageFactor(String className) {
        IMessage instance = null;
        try {
            instance = (IMessage) Class.forName(className).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return instance;
    }

    public static <T> T Factor(String className, Class<T> clazz) {//clazz用来确定泛型以及泛型返回值
        T t = null;
        try {
            t = (T) Class.forName(className).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return t;
    }
}
